package com.glwan.fixedassetapp.utils;

import com.tencent.mmkv.MMKV;

import java.util.Set;

public class MMKVSingleton {

    // 私有化构造函数
    private MMKVSingleton() {
    }

    /**
     * 获取 MMKV 的单例实例。
     *
     * @return MMKV 的单例实例。
     */
    public static MMKV getInstance() {
        return MmkvInstanceHolder.mmkvInstance;
    }

    // String
    public static void putString(String key, String value) {
        getInstance().putString(key, value);
    }

    public static String getString(String key, String defaultValue) {
        return getInstance().getString(key, defaultValue);
    }

    // int
    public static void putInt(String key, int value) {
        getInstance().putInt(key, value);
    }

    public static int getInt(String key, int defaultValue) {
        return getInstance().getInt(key, defaultValue);
    }

    // boolean
    public static void putBoolean(String key, boolean value) {
        getInstance().putBoolean(key, value);
    }

    public static boolean getBoolean(String key, boolean defaultValue) {
        return getInstance().getBoolean(key, defaultValue);
    }

    // float
    public static void putFloat(String key, float value) {
        getInstance().putFloat(key, value);
    }

    public static float getFloat(String key, float defaultValue) {
        return getInstance().getFloat(key, defaultValue);
    }

    // long
    public static void putLong(String key, long value) {
        getInstance().putLong(key, value);
    }

    public static long getLong(String key, long defaultValue) {
        return getInstance().getLong(key, defaultValue);
    }

    // Set<String>
    public static void putStringSet(String key, Set<String> value) {
        getInstance().putStringSet(key, value);
    }

    public static Set<String> getStringSet(String key, Set<String> defaultValue) {
        return getInstance().getStringSet(key, defaultValue);
    }

    private static final class MmkvInstanceHolder {
        static final MMKV mmkvInstance = MMKV.defaultMMKV();
    }
}
